package fr.thread.threadfactory.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.DatePicker;
import android.widget.DatePicker.OnDateChangedListener;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import fr.thread.threadfactory.R;

/**
 * 
 * @author fred
 *
 */
public class InterfaceActivity extends Activity {

	@Override
	public void onCreate(Bundle savedInstance){
		super.onCreate(savedInstance);
		
		setContentView(R.layout.interfaceactivity);
	
		bindActions();
		
	}
	
	private void bindActions(){
		// la gestion d'une checkbox
		CheckBox checkBox = (CheckBox)findViewById(R.id.checkBox);
		checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				Toast.makeText(getApplicationContext(), "Case cochée: "+isChecked, Toast.LENGTH_SHORT).show();
			}
		});
		
		// la gestion d'un radiogroup
		RadioGroup radioGroup = (RadioGroup)findViewById(R.id.radioGroup);
		android.widget.RadioGroup.OnCheckedChangeListener listener = new android.widget.RadioGroup.OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				RadioButton radioBI = (RadioButton)findViewById(checkedId);
				Toast.makeText(getApplicationContext(), radioBI.getText(), Toast.LENGTH_SHORT).show();
				
			}
		};
		radioGroup.setOnCheckedChangeListener(listener); 
		
		
		// Date Picker
		DatePicker datePicker = (DatePicker)findViewById(R.id.datePicker);
		datePicker.init(2012, 10, 19, new OnDateChangedListener() {
			
			@Override
			public void onDateChanged(DatePicker view, int year, int monthOfYear,
					int dayOfMonth) {
				Toast.makeText(getApplicationContext(), dayOfMonth+"/"+monthOfYear+"/"+year, Toast.LENGTH_SHORT).show();
			}
		});
		
		
	}
	
	public void onInputButton(View target){
		int idTarget = target.getId();
		
		// on filtre selon les ids
		switch (idTarget) {
		case R.id.okButton:{
			EditText nameField = (EditText)findViewById(R.id.nameField);
			Toast.makeText(getApplicationContext(), nameField.getText().toString(), Toast.LENGTH_LONG).show();
			break;
		}
		case R.id.imageButton:{
			Toast.makeText(getApplicationContext(), "logo", Toast.LENGTH_LONG).show();
		}
		default:
			break;
		}
	}
}
